<?php

namespace app\admin\model;
use think\Model;

//客户模型
class Member extends Model
{

    public static function paramsNew() :array {
        return array(
            'unionid' => '',
            'openid' => '',
            'mpopenid' => '',
            'using_category' => '',
            'username' => '',
            'password_hash' => '',
            'auth_key' => '',
            'password_reset_token' => '',
            'type' => 1,
            'nickname' => '',
            'realname' => '',
            'head_portrait' => '',
            'current_level' => '',
            'gender' => 1,
            'qq' => '',
            'email' => '',
            'visit_count' => '',
            'home_phone' => '',
            'mobile' => '',
            'role' => '',
            'last_time' => '',
            'last_ip' => '',
            'province_id' => '',
            'city_id' => '',
            'area_id' => '',
            'pid' => '',
            'level' => '',
            'promo_code' => '',
            'tree' => '',
            'merchant_id' => 0,
            'status' => 1,
            'created_at' => time(),
            'updated_at' => time(),
            'userinfoId' => 0,
        );
    }
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'hxdc_project_huxin';
    }

    /**
     * {@inheritdoc}
     */
//    public function rules()
//    {
//        return [
//            [['merchant_id', 'project_id', 'album_id', 'open_time', 'delivery_time','sort', 'created_at', 'updated_at', 'status'], 'integer'],
//            [['project_id', 'album_id'], 'required'],
//            [['title', 'hx_desc', 'telphone', 'prices'], 'string', 'max' => 20],
//            [['space_all', 'space_in', 'property_type', 'facing', 'huxing_structure'], 'string', 'max' => 10],
//            [['comment'], 'string', 'max' => 255],
//        ];
//    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [

        ];
    }
    /**
     * @param bool $insert
     * @return bool
     * @throws \yii\base\Exception
     */
    public function beforeSave($insert)
    {
        if ($this->isNewRecord) {
            $this->created_at = time();
        }

        return parent::beforeSave($insert);
    }
    /**
     * @return array
     */
    public function behaviors()
    {
        $merchant_id = Yii::$app->services->merchant->getId();
        return [
            [
                'class' => TimestampBehavior::class,
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
            [
                'class' => BlameableBehavior::class,
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['merchant_id'],
                ],
                'value' => !empty($merchant_id) ? $merchant_id : 0,
            ]
        ];
    }
}
